<template>
	<view>
		<u-navbar :background="background" :borderBottom="false">
			<view class="ft_16 fw-b">
				确认订单
			</view>
		</u-navbar>
		<view class="content">
			<view class="con_1 card">
				<view class="display just_space" @click="selectAddress">
					<view class="" v-if="!addressInfo">
						请选择收货地址
					</view>
					<view class="" v-else> 
						<view class=" text_hidden1 ft_16 fw-b">
							{{addressInfo.addresss}}
						</view>
						<view class="p_top_10 c-999">
							<text class="p_right_10">{{addressInfo.name}}</text>
							<text>{{addressInfo.mobile}}</text>
						</view>
					</view>
					<u-icon name="arrow-right" color="#999999" size="28"></u-icon>
				</view>
			</view>
			<!-- 商品信息 -->
			<view class="card con_2">
				<view class="display shopinfo">
					<view class="shopimg">
						<image :src="shopInfo.image" mode="aspectFill"></image>
					</view>
					<view class="shoptext">
						<view class="">
							<view class="fw-b text_hidden2">{{shopInfo.name}}</view>
							<view class="ft_12 c-999 p_top_10">
								{{shopInfo.item_name}}
							</view>
						</view>
						<view class="ft_14 fw-b">
							<text class="ft_20">{{shopInfo.price}}积分</text>
						</view>
					</view>
				</view>
			</view>
			
			<view style="height: 100rpx;"></view>
			<view class="bottom_bar display just_space">
				<view class="c-red ft_18 fw-b p_left_10">
					{{shopInfo.price}}积分
				</view>
				<view class="submitBtn" @click="show=true">
					提交订单
				</view>
			</view>
			
		</view>
		
		<!-- 确认兑换 -->
		<u-modal v-model="show" title="确认兑换" :title-style="{fontWeight: 700}" :show-cancel-button	="true" confirm-color	="#ef9e20" @confirm="suborder">
			<view class="ft_14" style="text-align: center;padding: 20px 0;">
				本次兑换需要消耗
				<text style="color: #ef9e20;">{{shopInfo.price}}</text>
				积分，是否兑换？
			</view>
		</u-modal>
		<!-- 选择优惠券弹窗 -->
		<!-- <u-popup v-model="show" mode="bottom" border-radius="14" closeable></u-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background:{backgroundColor: '#ffffff',},
				addressInfo:'', //收货地址
				shopInfo:{},
				shopid:6, //商品id
				
				show:false, //是否兑换
				
			}
		},
		onLoad(e) {
			console.log(e);
			uni.$on('address',res=>{
				console.log(res);
				this.addressInfo=res
			})
			if(e.shopid){
				this.shopid=e.shopid
			}
			this.getshopInfo()  //获取商品跟地址信息
		},
		methods: {
			getshopInfo(){ //获取商品跟地址信息
				this.$myRequest('order/confirm_integral',{
					goods_id:this.shopid
				}).then(res=>{
					console.log(res.data.data);
					let data=res.data.data
					let address=data.address //默认地址
					address.addresss=address.province_name+address.city_name+address.area_name+address.address
					this.addressInfo=data.address
					
					this.shopInfo= Object.assign(data.goods, data.sku_product)
					this.shopInfo.item_name=this.shopInfo.item_name.replace(/;/g,' ') //去掉分号
					console.log(this.shopInfo);
				})
			},
			
			selectAddress(){ //选择地址
				uni.navigateTo({
					url:"../../mine/shAddress?type="+0
				})
			},
			suborder(){ //提交订单
				console.log(this.addressInfo);
				if(!this.addressInfo){
					this.$all.toast("请选择收货地址")
					return
				}
				this.$myRequest('order/order_integral',{
					goods_id:this.shopid,
					address_id:this.addressInfo.id,
					remark:''
				}).then(res=>{
					console.log(res.data);
					this.$all.toast(res.data.msg)
					let data=res.data.data
					if(res.data.code==1){
						setTimeout(()=>{
							uni.reLaunch({ 
								url:"DHscuuess?shopid="+this.shopid+"&ordernum="+data.order_no
							})
						},800)
					}
				})
			},
			
		}
	}
</script>

<style lang="scss">
page{
	background-color: #fafafa;
}

.content{
	padding-top: 10px;
	.card{
		padding: 15px;
		background-color: #FFFFFF;
		margin-bottom: 10px;
	}
	
	.con_2{
		.shopinfo{
			border-bottom: 1px solid #eeeeee;
			padding-bottom: 15px;
			.shopimg{
				width: 200rpx;height: 200rpx;margin-right: 10px;
				image{
					width: 200rpx;height: 200rpx;border-radius: 5px;
				}
			}
			.shoptext{
				display: flex;justify-content: space-between;flex-flow: column;height: 100px;
			}
		}
	}
	
	.bottom_bar{
		height: 100rpx;width: 100%;background-color: #FFFFFF;position: fixed;bottom: 0;
		.submitBtn{
			width: 40%;height: 100rpx;line-height: 100rpx;color: #FFFFFF;text-align: center;background: linear-gradient(90deg, #F1A421 0%, #E4741F 100%);
		}
	}
	
}

</style>
